<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

<!-- jQuery  -->
   <script type="text/javascript" src="/plugins/jquery/jquery-3.6.0.min.js"></script>

<!-- layui  -->
<link rel="stylesheet" href="/plugins/layui/2.7.6/css/layui.css" media="all" />
<script src="/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>

</head>

<body>
	<form class="layui-form" id="id_form" method="post" action="/storage/stockope/importBatch">
		<div class="layui-form-item">
			<div class="layui-col-md5">
				<label class="layui-form-label">上传EXCEL</label>
				<div class="layui-input-block">
					<input type="text" name="link" readonly="readonly" placeholder="尚未选择文件，请点击此处选择" class="layui-input" lay-verify="required">
					<script>
					layui.use(['upload','table'], function(){
						var dom = $('input[name="link"]');
						var indexOfLoading;
						layui.upload.render({
							elem: dom,
							accept: 'file',
							acceptMime: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
							ext: 'xlsx',
							url: '/storage/stockope/uploadAndReadExcelBatchImport',
							multiple: false,
							progress: function(n, elem){
								dom.val(n + '%');
								indexOfLoading = layer.load(1, {
									shade: [0.5,'#000000'] //0.1透明度的白色背景
								});
							},
							done: function(res){
								layer.close(indexOfLoading);
								if (res.code == 0) {
									layer.msg('解析成功');
									window.importTable = layui.table.render({
										elem: '#id_table_merchant_goods',
										height: 500,
										width: 1500,
										limit: 9999,
										id: dom.attr('id'),
										totalRow: true,
										cols: [ [
												{field: 'index', title: '序号', align:'center', width: 60},
												{field: 'guid', title: '唯一标识', align:'center'},
												{field: 'codeProduct', title: '商品编码', align:'center'},
												{field: 'codeCompany', title: '公司编码', align:'center'},
												{field: 'nameCompany', title: '公司全称', align:'center'},
												{field: 'nameCompanyShort', title: '公司简称', align:'center'},
												{field: 'locationArea', title: '所在仓', align:'center'},
												{field: 'locationKq', title: '库区', align:'center'},
												{field: 'locationHw', title: '货位', align:'center'},
												{field: 'num', title: '变动数量', align:'center'},
												{field: 'remark', title: '备注', align:'center'}
										] ],
										data: res.data.rows
									});
									/*
									dom.val(res.url);
									layer.msg('上传成功');
									
									$("#id_calculate").val("计算中...");
									$.ajax({
										type: "POST",
										url: "/api/inter/asinLog/readExcel",
										data: {url: res.url},
										success: function (data) {
											$("#id_calculate").val(data.msg);
										},error(){
											alert("ajax错误！");
										}
									});
									*/
								} else{//如果上传失败
									return layer.msg(res.msg);
								}
							}
						});
					});
					</script>
				</div>
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-col-md1 layui-col-md-offset11">
				<div class="layui-btn-container">
					<!-- <button type="button" class="layui-btn" onclick="doTest()">获取数据</button> -->
					<button type="button" class="layui-btn" onclick="window.open('/importMuban/模板_库存修改单.xlsx', '_blank')">下载模板</button>
					<button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">保存</button>
				</div>
			</div>
		</div>
	
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend>表格信息</legend>
		</fieldset>
		<div class="layui-upload">
			<div class="layui-upload-list">
				<table class="layui-table">
					<table class="layui-hide" id="id_table_merchant_goods"></table>
				</table>
			</div>
		</div>
	</div>
</form>
<script>
$(function () {
	layui.use(['form'], function(){
		var form = layui.form;
		
		// 表单提交，共用同一个
		form.on('submit(formSubmit)', function(data){
			var formData = $('#id_form').serialize();
			formData = formData + "&detailArr=" + JSON.stringify(layui.table.getData('id_table_merchant_goods'));
			var indexOfLoading = layer.load(1, {
				shade: [0.5,'#000000'] //0.1透明度的白色背景
			});
			$.post(data.form.action, formData, function(res){
				console.log(res);
				if (res.code == 0) {
					layer.msg(res.msg);
					layer.close(indexOfLoading);
				} else {
					layer.close(indexOfLoading);
					layer.msg(res.msg);
				}
			});
			return false;
		});
	});
});
</script>
</body>

</html>